﻿@model Mrc.Entity.UserProjectDemand
@{
    ViewData["Title"] = "Add";
    Layout = "~/Areas/Admin/Views/_Layout.cshtml";
    var prioritys = System.EnumExtension.GetDic<Mrc.Entity.ProjectPriorityEnums>();
    var taskTypes = System.EnumExtension.GetDic<Mrc.Entity.ProjectTaskTypeEnum>();

}
<link href="~/lib/layui-select/formSelects-v4.css" rel="stylesheet" />
<div style="margin-top:3em;margin-right:5em">
    <form class="layui-form" action="">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">任务名称</label>
            <div class="layui-input-block">
                <input type="text" name="Name" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">需求名称</label>
                <div class="layui-input-block">
                    <input type="text" name="DemandId" value="@Model.Id" class="layui-hide" />
                    <input type="text" name="DemandName" value="@Model.Name" required placeholder="" autocomplete="off" class="layui-input" readonly>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">执行人</label>
                <div class="layui-input-block">
                    <select name="ExecuteUId" id="ExecuteUId" xm-select="ExecuteUId" xm-select-search="" xm-select-radio=""></select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">计划时间</label>
                <div class="layui-input-block">
                    <input type="text" name="PlanStarTime" id="PlanStarTime" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-block">
                    <input type="text" name="PlanFinishTime" id="PlanFinishTime" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">任务类型</label>
                <div class="layui-input-block">
                    <select name="Type" id="Type" xm-select="Type" xm-select-search="" xm-select-radio="">
                        @foreach (var item in taskTypes)
                        {
                            <option value="@item.Key">@item.Value</option>
                        }
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">优先级</label>
                <div class="layui-input-block">
                    <select name="Priority" id="Priority" xm-select="Priority" xm-select-search="" xm-select-radio="">
                        @foreach (var item in prioritys)
                        {
                            <option value="@item.Key">@item.Value</option>
                        }
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">关联项目</label>
            <div class="layui-input-block">
                <select name="ProjectId" id="ProjectId" xm-select="ProjectId" xm-select-search="" xm-select-radio=""></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">关联人员</label>
            <div class="layui-input-block">
                <select name="userIds" id="userIds" xm-select="userIds" xm-select-search=""></select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="Description" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    //Demo
    //全局定义一次, 加载formSelects
    layui.config({
        base: '/lib/layui-select/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });
    layui.use(['form', 'formSelects', 'laydate'], function () {
        var form = layui.form;
        var formSelects = layui.formSelects;
        var laydate = layui.laydate;
        var laydate2 = layui.laydate;

        laydate.render({
            elem: '#PlanStarTime'
        });
        laydate2.render({
            elem: '#PlanFinishTime'
        });
        $.get("/project/ProjectTask/GetSelectData", function (repo) {
            var html = '';
            $.each(repo.data, function (index, item) {
                html += '<option value="' + item.value + '">' + item.name + '</option>';
            });
            $("#ExecuteUId").html(html);
            $("#userIds").html(html);    
            formSelects.render();
        });

        $.get("/project/project/GetSelectData", function (repo) {
            var html = '';
            $.each(repo.data, function (index, item) {
                html += '<option value="' + item.value + '" ' + contiansKey('@(Model.ProjectId??"")', item.value) + '>' + item.name + '</option>';
            });
            $("#ProjectId").html(html);
            formSelects.render();
        });


        //监听提交
        form.on('submit(formDemo)', function (data) {
            BaseAjax(ajaxType.post, "/project/ProjectTask/add", data.field, function (repo) {
                if (repo.status == ajaxStatus.OK)
                  x_admin_close();
            })
            return false;
        });
    });

    function contiansKey(str, target) {
        if (str == "" || str == null) return "";
        return str.indexOf(target) == -1 ? '' : 'selected="selected"';
    }
</script>
